{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d29d8bf0",
   "metadata": {},
   "source": [
    "## 1. 管理工具安装\n",
    "### 1.1 langchain 安装"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c5656e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install langchain\n",
    "\n",
    "# conda \n",
    "# conda install -c conda-forge langchain"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a14385d",
   "metadata": {},
   "source": [
    "### 1.2 其他库安装"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6ca6de9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 直接转换为 REST API\n",
    "!pip install \"langserve[all]\"\n",
    "\n",
    "# 观测平台\n",
    "!pip install -U langsmith\n",
    "\n",
    "# LangGraph\n",
    "!pip install -U langgraph\n",
    "\n",
    "# DeepSeek\n",
    "!pip install langchain-deepseek\n",
    "\n",
    "# 外部资源集成\n",
    "!pip install langchain_community\n",
    "\n",
    "# dotenv管理密钥，加载环境变量等\n",
    "!pip install python-dotenv"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abacf945",
   "metadata": {},
   "source": [
    "### 1.3 常见的处理链包含三个要素\n",
    "\n",
    "1. 语言模型：核心推理引擎\n",
    "2. 提示词模板：提供指令\n",
    "3. 输出解释器：转换为易于使用的格式，便于下游处理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dcd7232d",
   "metadata": {},
   "source": [
    "#### 1.3.1 语言模型\n",
    "\n",
    "langchain语言模型主要分为两种：\n",
    "\n",
    "1. LLM 通用模型：接收字符串作为输入，输出字符串作为输出。\n",
    "2. ChatModel 对话模型：接收消息列表，输出“消息”，用于一问一答。\n",
    "\n",
    "消息：由 BaseMessage 类定义，包含文本、时间戳、用户标识符等属性。主要的有\n",
    "\n",
    "1. 消息的内容：文本，通常是字符串\n",
    "2. 角色：消息的发送方\n",
    "\n",
    "角色： LangChain 用于区分不同角色的对象\n",
    "\n",
    "1. HumanMessage：人类（用户）输入的BaseMessage。\n",
    "2. AIMessage：AI助手（大模型）输出的BaseMessage。\n",
    "3. SystemMessage：系统预设的BaseMessage。\n",
    "4. FunctionMessage：自定义函数输出的BaseMessage。\n",
    "5. ToolMessage：调用第三方工具输出的BaseMessage。\n",
    "6. ChatMessage：自定义角色。\n",
    "\n",
    "方法： LCEL 默认实现同步调用方法，最常见的是 invoke 方法，接受一个 BaseMessage 对象作为参数，并返回一个 BaseMessage 对象作为结果。\n",
    "\n",
    "比如：\n",
    "LLMs.invoke：输入输出都是字符串\n",
    "ChatModels.invoke：输入输出都是BaseMessage对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6626b9ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好呀！✨ 很高兴见到你！今天过得怎么样呀？希望你度过了愉快的一天。我随时准备好陪你聊天、帮你解决问题，或者就这样轻松愉快地闲聊一会儿。有什么想跟我分享的吗？ 🌟\n",
      "你好！我这里无法直接获取你所在地的实时天气信息。你可以告诉我你所在的城市或地区，我可以帮你提供一些查询天气的建议，或者你可以使用天气应用查看实时天气哦！\n"
     ]
    }
   ],
   "source": [
    "from langchain_community.llms.tongyi import  Tongyi\n",
    "\n",
    "llm = Tongyi()\n",
    "\n",
    "\n",
    "print(llm.invoke(\"你好\"))\n",
    "print(llm(\"你好，今天天气怎么样？\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24354c9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='你好！很高兴见到你，有什么可以帮你的吗？😊' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 14, 'prompt_tokens': 5, 'total_tokens': 19, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 0}, 'prompt_cache_hit_tokens': 0, 'prompt_cache_miss_tokens': 5}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_08f168e49b_prod0820_fp8_kvcache', 'id': 'b091f984-a197-42cb-94d1-80bfc1bb8631', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None} id='run--924ee09c-7aac-4ee1-b148-613099d36b53-0' usage_metadata={'input_tokens': 5, 'output_tokens': 14, 'total_tokens': 19, 'input_token_details': {'cache_read': 0}, 'output_token_details': {}}\n"
     ]
    }
   ],
   "source": [
    "from langchain_deepseek import ChatDeepSeek\n",
    "\n",
    "deepseek = ChatDeepSeek(model=\"deepseek-chat\")\n",
    "\n",
    "print(deepseek.invoke(\"你好\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb387ed8",
   "metadata": {},
   "source": [
    "#### 1.3.2 提示词模板\n",
    "\n",
    "提示词模板是用于生成提示词的模板。例如，`{name}，你好！我是你的朋友小爱同学。`就是一个提示词模板。\n",
    "\n",
    "提示词模板中可以使用变量，变量名由字母、数字和下划线组成，且必须以字母开头。例如，`{name}，你好！我是你的朋友小爱同学。`中的`{name}`就是一个变量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33c14018",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Hello, I am a chatbot. How can I help you today?'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.prompts import PromptTemplate\n",
    "\n",
    "prompt = PromptTemplate.from_template(\n",
    "    \"Hello, I am a {model_name}. How can I help you today?\"\n",
    ")\n",
    "prompt.format(model_name=\"chatbot\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ced305f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "system: You are a helpful AI assistant named Claude.\n",
      "human: Hello, my name is Alice. What's the weather like today?\n"
     ]
    }
   ],
   "source": [
    "# 使用 ChatPromptTemplate 创建对话模板\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "\n",
    "# 创建包含 system 和 human 消息的聊天模板\n",
    "chat_prompt = ChatPromptTemplate.from_messages([\n",
    "    (\"system\", \"You are a helpful AI assistant named {assistant_name}.\"),\n",
    "    (\"human\", \"Hello, my name is {user_name}. {question}\")\n",
    "])\n",
    "\n",
    "# 格式化消息\n",
    "messages = chat_prompt.format_messages(\n",
    "    assistant_name=\"Claude\",\n",
    "    user_name=\"Alice\", \n",
    "    question=\"What's the weather like today?\"\n",
    ")\n",
    "\n",
    "for message in messages:\n",
    "    print(f\"{message.type}: {message.content}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "01358291",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "    请为初学者写一篇关于人工智能的文章。\n",
      "    写作风格应该是通俗易懂的。\n",
      "\n",
      "    文章要求：\n",
      "    - 内容准确且有用\n",
      "    - 结构清晰\n",
      "    - 适合目标受众\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "from langchain_core.prompts import PromptTemplate\n",
    "\n",
    "# 多变量模板\n",
    "complex_prompt = PromptTemplate(\n",
    "    input_variables=[\"topic\", \"audience\", \"tone\"],\n",
    "    template=\"\"\"\n",
    "    请为{audience}写一篇关于{topic}的文章。\n",
    "    写作风格应该是{tone}的。\n",
    "    \n",
    "    文章要求：\n",
    "    - 内容准确且有用\n",
    "    - 结构清晰\n",
    "    - 适合目标受众\n",
    "    \"\"\"\n",
    ")\n",
    "\n",
    "formatted_prompt = complex_prompt.format(\n",
    "    topic=\"人工智能\",\n",
    "    audience=\"初学者\",\n",
    "    tone=\"通俗易懂\"\n",
    ")\n",
    "print(formatted_prompt)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d94571bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "分析以下销售数据：\n",
      "Q1销售额: 100万, Q2销售额: 120万\n",
      "\n",
      "请提供趋势分析。\n"
     ]
    }
   ],
   "source": [
    "from langchain_core.prompts import PromptTemplate\n",
    "\n",
    "# f-string 风格、jinja2语法 ...\n",
    "f_string_prompt = PromptTemplate.from_template(\n",
    "    \"分析以下{data_type}数据：\\n{data}\\n\\n请提供{analysis_type}分析。\"\n",
    ")\n",
    "\n",
    "result = f_string_prompt.format(\n",
    "    data_type=\"销售\",\n",
    "    data=\"Q1销售额: 100万, Q2销售额: 120万\",\n",
    "    analysis_type=\"趋势\"\n",
    ")\n",
    "print(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "db878476",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_core.prompts import PromptTemplate\n",
    "\n",
    "# 带条件逻辑的模板\n",
    "conditional_prompt = PromptTemplate(\n",
    "    input_variables=[\"user_type\", \"question\"],\n",
    "    template=\"\"\"\n",
    "    {%- if user_type == \"expert\" -%}\n",
    "    作为专家，请详细回答：{question}\n",
    "    {%- else -%}\n",
    "    请用简单易懂的方式回答：{question}\n",
    "    {%- endif -%}\n",
    "    \"\"\"\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61bffdf3",
   "metadata": {},
   "source": [
    "#### 1.3.3 输出解析器\n",
    "\n",
    "输出解析器是 LangChain 中的重要组件，用于将大语言模型(LLM)的原始文本输出转换为结构化数据格式，便于程序进一步处理和使用。\n",
    "\n",
    "主要功能\n",
    "- 格式化输出: 将 LLM 的自然语言输出解析为 JSON、XML、列表等结构化格式\n",
    "- 类型转换: 将文本数据转换为 Python 对象（字典、列表、自定义类等）\n",
    "- 数据验证: 确保输出符合预期的格式和约束条件\n",
    "- 错误处理: 处理解析失败的情况，提供重试机制\n",
    "\n",
    "常见的输出解析器类型\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a5fde359",
   "metadata": {},
   "outputs": [],
   "source": [
    "# JSON 输出解析器\n",
    "from langchain.output_parsers import PydanticOutputParser\n",
    "from pydantic import BaseModel, Field\n",
    "\n",
    "class PersonInfo(BaseModel):\n",
    "    name: str = Field(description=\"人物姓名\")\n",
    "    age: int = Field(description=\"年龄\")\n",
    "    occupation: str = Field(description=\"职业\")\n",
    "\n",
    "parser = PydanticOutputParser(pydantic_object=PersonInfo)\n",
    "\n",
    "# 列表输出解析器\n",
    "\n",
    "from langchain.output_parsers import CommaSeparatedListOutputParser\n",
    "\n",
    "parser = CommaSeparatedListOutputParser()\n",
    "# 将 \"苹果,香蕉,橙子\" 解析为 [\"苹果\", \"香蕉\", \"橙子\"]\n",
    "\n",
    "# 结构化输出解析器\n",
    "from langchain.output_parsers import StructuredOutputParser, ResponseSchema\n",
    "\n",
    "response_schemas = [\n",
    "    ResponseSchema(name=\"answer\", description=\"问题的答案\"),\n",
    "    ResponseSchema(name=\"source\", description=\"答案来源\")\n",
    "]\n",
    "parser = StructuredOutputParser.from_response_schemas(response_schemas)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c5ecc570",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "手动解析结果: ['Python', 'Java', 'JavaScript', 'C++', 'Go']\n"
     ]
    }
   ],
   "source": [
    "# 手动使用解析器\n",
    "parser = CommaSeparatedListOutputParser()\n",
    "\n",
    "# 模拟 LLM 的原始输出\n",
    "raw_output = \"Python, Java, JavaScript, C++, Go\"\n",
    "\n",
    "# 解析输出\n",
    "parsed_result = parser.parse(raw_output)\n",
    "print(\"手动解析结果:\", parsed_result)\n",
    "# 输出: ['Python', 'Java', 'JavaScript', 'C++', 'Go']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1c96059",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "水果列表: ['apple', 'banana', 'orange', 'grape', 'strawberry']\n",
      "编程语言列表: ['Python', 'Java', 'C++', 'JavaScript', 'Ruby']\n"
     ]
    }
   ],
   "source": [
    "from langchain.output_parsers import CommaSeparatedListOutputParser\n",
    "from langchain_community.llms import Tongyi\n",
    "\n",
    "# 初始化\n",
    "parser = CommaSeparatedListOutputParser()\n",
    "llm = Tongyi(temperature=0)\n",
    "\n",
    "# 直接构建提示并调用\n",
    "def simple_list_generation(category):\n",
    "    # 手动构建提示\n",
    "    prompt = f\"\"\"请列出5个{category}的例子。\n",
    "{parser.get_format_instructions()}\"\"\"\n",
    "    \n",
    "    # 直接调用LLM\n",
    "    response = llm.invoke(prompt)\n",
    "    \n",
    "    # 解析结果\n",
    "    return parser.parse(response)\n",
    "\n",
    "\n",
    "# 使用\n",
    "fruits = simple_list_generation(\"水果\")\n",
    "print(\"水果列表:\", fruits)\n",
    "\n",
    "languages = simple_list_generation(\"编程语言\")\n",
    "print(\"编程语言列表:\", languages)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec799790",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "格式化指令: Your response should be a list of comma separated values, eg: `foo, bar, baz` or `foo,bar,baz`\n",
      "解析后的结果: ['苹果', '香蕉', '橙子', '葡萄', '草莓']\n",
      "结果类型: <class 'list'>\n",
      "1. 苹果\n",
      "2. 香蕉\n",
      "3. 橙子\n",
      "4. 葡萄\n",
      "5. 草莓\n",
      "\n",
      "=== 编程语言 ===\n",
      "• Python\n",
      "• Java\n",
      "• C++\n",
      "• JavaScript\n",
      "• Ruby\n",
      "\n",
      "=== 运动项目 ===\n",
      "• 篮球\n",
      "• 足球\n",
      "• 网球\n",
      "• 游泳\n",
      "• 田径\n",
      "\n",
      "=== 乐器 ===\n",
      "• 钢琴\n",
      "• 吉他\n",
      "• 小提琴\n",
      "• 鼓\n",
      "• 长笛\n"
     ]
    }
   ],
   "source": [
    "from langchain.output_parsers import CommaSeparatedListOutputParser\n",
    "from langchain_core.prompts import PromptTemplate\n",
    "from langchain_community.llms.tongyi import Tongyi\n",
    "\n",
    "# 1. 创建输出解析器\n",
    "parser = CommaSeparatedListOutputParser()\n",
    "\n",
    "# 2. 获取格式化指令\n",
    "format_instructions = parser.get_format_instructions()\n",
    "print(\"格式化指令:\", format_instructions)\n",
    "\n",
    "# 3. 创建包含格式指令的提示模板\n",
    "prompt = PromptTemplate(\n",
    "    template=\"请列出5个{category}的例子。\\n{format_instructions}\",\n",
    "    input_variables=[\"category\"],\n",
    "    partial_variables={\"format_instructions\": format_instructions}\n",
    ")\n",
    "\n",
    "# 4. 初始化 LLM\n",
    "llm = Tongyi(temperature=0)\n",
    "\n",
    "# 5. 创建完整的链\n",
    "chain = prompt | llm | parser\n",
    "\n",
    "# 6. 使用示例\n",
    "try:\n",
    "    # 调用链并获取解析后的结果\n",
    "    result = chain.invoke({\"category\": \"水果\"})\n",
    "    print(\"解析后的结果:\", result)\n",
    "    print(\"结果类型:\", type(result))\n",
    "    # 输出示例: ['苹果', '香蕉', '橙子', '葡萄', '草莓']\n",
    "    \n",
    "    # 遍历结果\n",
    "    for i, fruit in enumerate(result, 1):\n",
    "        print(f\"{i}. {fruit}\")\n",
    "        \n",
    "except Exception as e:\n",
    "    print(f\"解析错误: {e}\")\n",
    "\n",
    "# 7. 更复杂的示例 - 多个类别\n",
    "categories = [\"编程语言\", \"运动项目\", \"乐器\"]\n",
    "\n",
    "for category in categories:\n",
    "    print(f\"\\n=== {category} ===\")\n",
    "    try:\n",
    "        result = chain.invoke({\"category\": category})\n",
    "        for item in result:\n",
    "            print(f\"• {item}\")\n",
    "    except Exception as e:\n",
    "        print(f\"处理 {category} 时出错: {e}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ac7bafd6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "早餐购物清单: ['牛奶', '鸡蛋', '面包', '黄油', '燕麦片']\n",
      "午餐购物清单: ['面包', '火腿', '生菜', '番茄', '奶酪']\n",
      "晚餐购物清单: ['鸡胸肉', '西兰花', '红椒', '大蒜', '橄榄油']\n",
      "\n",
      "=== 详细购物清单 ===\n",
      "\n",
      "🍽️ 早餐:\n",
      "  1. 牛奶\n",
      "  2. 鸡蛋\n",
      "  3. 面包\n",
      "  4. 黄油\n",
      "  5. 燕麦片\n",
      "\n",
      "🍽️ 午餐:\n",
      "  1. 面包\n",
      "  2. 火腿\n",
      "  3. 生菜\n",
      "  4. 番茄\n",
      "  5. 奶酪\n",
      "\n",
      "🍽️ 晚餐:\n",
      "  1. 鸡胸肉\n",
      "  2. 西兰花\n",
      "  3. 红椒\n",
      "  4. 大蒜\n",
      "  5. 橄榄油\n"
     ]
    }
   ],
   "source": [
    "# 购物清单\n",
    "from langchain.output_parsers import CommaSeparatedListOutputParser\n",
    "from langchain_core.prompts import PromptTemplate\n",
    "from langchain_community.llms import Tongyi\n",
    "\n",
    "# 1. 初始化组件\n",
    "parser = CommaSeparatedListOutputParser()\n",
    "llm = Tongyi(temperature=0)\n",
    "\n",
    "# 2. 创建提示模板\n",
    "shopping_prompt = PromptTemplate(\n",
    "    template=\"根据{meal_type}，生成一个包含5个食材的购物清单。\\n{format_instructions}\",\n",
    "    input_variables=[\"meal_type\"],\n",
    "    partial_variables={\"format_instructions\": parser.get_format_instructions()}\n",
    ")\n",
    "\n",
    "# 3. 创建链\n",
    "shopping_chain = shopping_prompt | llm | parser\n",
    "\n",
    "# 4. 生成不同餐型的购物清单\n",
    "meals = [\"早餐\", \"午餐\", \"晚餐\"]\n",
    "shopping_lists = {}\n",
    "\n",
    "for meal in meals:\n",
    "    shopping_lists[meal] = shopping_chain.invoke({\"meal_type\": meal})\n",
    "    print(f\"{meal}购物清单: {shopping_lists[meal]}\")\n",
    "\n",
    "# 5. 格式化输出\n",
    "print(\"\\n=== 详细购物清单 ===\")\n",
    "for meal, items in shopping_lists.items():\n",
    "    print(f\"\\n🍽️ {meal}:\")\n",
    "    for i, item in enumerate(items, 1):\n",
    "        print(f\"  {i}. {item}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b006350b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "早餐食材: ['鸡蛋', '牛奶', '面包', '燕麦', '香蕉']\n",
      "办公室用品: ['Pen', 'Notebook', 'Stapler', 'Printer', 'Coffee Maker']\n",
      "旅行必需品: ['护照', '钱包', '手机充电器', '水杯', '防晒霜']\n",
      "健身器材: ['哑铃', '杠铃', '引体向上杆', '健身球', '跳绳']\n",
      "学习工具: ['Anki', 'Quizlet', 'Notion', 'Duolingo', 'Khan Academy']\n"
     ]
    }
   ],
   "source": [
    "# 多场景\n",
    "from langchain.output_parsers import CommaSeparatedListOutputParser\n",
    "from langchain_core.prompts import PromptTemplate\n",
    "from langchain_community.llms import Tongyi\n",
    "\n",
    "# 通用列表生成链\n",
    "parser = CommaSeparatedListOutputParser()\n",
    "list_chain = (\n",
    "    PromptTemplate(\n",
    "        template=\"请列出5个{category}的{item_type}。\\n{format_instructions}\",\n",
    "        input_variables=[\"category\", \"item_type\"],\n",
    "        partial_variables={\"format_instructions\": parser.get_format_instructions()}\n",
    "    )\n",
    "    | Tongyi(temperature=0)\n",
    "    | parser\n",
    ")\n",
    "\n",
    "# 多场景使用\n",
    "scenarios = [\n",
    "    {\"category\": \"早餐\", \"item_type\": \"食材\"},\n",
    "    {\"category\": \"办公室\", \"item_type\": \"用品\"},\n",
    "    {\"category\": \"旅行\", \"item_type\": \"必需品\"},\n",
    "    {\"category\": \"健身\", \"item_type\": \"器材\"},\n",
    "    {\"category\": \"学习\", \"item_type\": \"工具\"}\n",
    "]\n",
    "\n",
    "for scenario in scenarios:\n",
    "    result = list_chain.invoke(scenario)\n",
    "    print(f\"{scenario['category']}{scenario['item_type']}: {result}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f802b31",
   "metadata": {},
   "source": [
    "#### 1.3.4 使用 LCEL 的好处\n",
    "\n",
    "1. 简洁语法: 使用管道操作符 | 创建链，代码直观易读\n",
    "2. 自动类型推断: 组件间数据类型自动转换，减少手动处理\n",
    "3. 并行处理: 内置并行执行能力，提高处理效率\n",
    "4. 流式处理: 原生支持流式输出，适合实时应用\n",
    "5. 智能缓存: 自动缓存中间结果，避免重复计算\n",
    "6. 内置调试: 更好的调试和监控能力\n",
    "7. 插件化: 支持自定义组件和扩展\n",
    "8. 标准接口: 统一的 Runnable 接口\n",
    "9. 版本管理: 支持链的版本控制和管理"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MLOps",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
